#include <stdio.h>
#include "wc.h"

int main() {
    int tests_passed = 0;
    
    // Create a test file "testfile.txt" for testing
    FILE *file = fopen("testfile.txt", "w");
    if (!file) {
        perror("Failed to create test file");
        return 1;
    }

    // Writing test content into "testfile.txt"
    fprintf(file, "Hello World!");
    fclose(file);

    Stats stats;
    init_stats(&stats);

    // Test count characters
    stats.chars = count_chars("testfile.txt");
    if (stats.chars == 12) {  // Expected character count
        printf("Character count test passed!\n");
        tests_passed++;
    }

    // Test count words
    stats.words = count_words("testfile.txt");
    if (stats.words == 2) {  // Expected word count
        printf("Word count test passed!\n");
        tests_passed++;
    }

    // Test count sentences
    stats.sentences = count_sentences("testfile.txt");
    if (stats.sentences == 1) {  // Expected sentence count
        printf("Sentence count test passed!\n");
        tests_passed++;
    }

    // Test count lines
    count_basic("testfile.txt", &stats);
    if (stats.lines == 1) {  // Expected line count
        printf("Line count test passed!\n");
        tests_passed++;
    }

    // Test count code lines
    count_extended("testfile.txt", &stats);
    if (stats.code_lines == 1) {  // Expected code lines count
        printf("Code line count test passed!\n");
        tests_passed++;
    }

    // Test count empty lines
    if (stats.empty_lines == 0) {  // Expected empty line count
        printf("Empty line count test passed!\n");
        tests_passed++;
    }

    // Test count comment lines
    if (stats.comment_lines == 0) {  // Expected comment line count
        printf("Comment line count test passed!\n");
        tests_passed++;
    }

    // Output the final test summary
    printf("%d tests passed!\n", tests_passed);

    // Clean up test file
    remove("testfile.txt");

    return 0;
}
